const local = window.localStorage;
const session = window.sessionStorage;

export const Local = {
  get(key) {
    if (!key) return;
    return JSON.parse(local.getItem(key) || null);
  },
  set(key, value) {
    if (!key) return;
    if (typeof value !== 'string') {
      value = JSON.stringify(value);
    }
    local.setItem(key, value);
  },
  remove(key) {
    if (!key) return;
    local.removeItem(key);
  },
  clear() {
    local.clear();
  }
};

export const Session = {
  get(key) {
    if (!key) return;
    return JSON.parse(session.getItem(key) || null);
  },
  set(key, value) {
    if (!key) return;
    if (typeof value !== 'string') {
      value = JSON.stringify(value);
    }
    session.setItem(key, value);
  },
  remove(key) {
    if (!key) return;
    session.removeItem(key);
  },
  clear() {
    session.clear();
  }
};
